<?php

class Admin_TintucDanhmuc1Controller extends Zend_Controller_Action{

    public function init()
    {
        $module=$this->_request->getModuleName();
        
        $this->view->headTitle()->set('Zend Framework');
        $this->view->headMeta()->getContainer()->exchangeArray(array());
        $this->view->headLink()->getContainer()->exchangeArray(array());
        $this->view->headScript()->getContainer()->exchangeArray(array());
        
        $config = new Zend_Config_Ini(APPLICATION_PATH."/templates/$module/install.ini","template");
        $config = $config->toArray();
        
        //Apply meta to layout
        if(count($config['metaHttp'])>0){      
            foreach ($config['metaHttp'] as $key => $value){
                $tmp = explode("||",$value);            
                $this->view->headMeta()->appendHttpEquiv($tmp[0],$tmp[1]);
            }
        }
      
        if(count($config['metaName'])>0){      
            foreach ($config['metaName'] as $key => $value){
                $tmp = explode("||",$value);            
                $this->view->headMeta()->appendName($tmp[0],$tmp[1]);
            }
        }
                        
        //Apply styles to layout
        if(count($config['filecss'])>0){      
            foreach ($config['filecss'] as $key => $css){
                $this->view->headLink()->appendStylesheet(BASE_URL."/application/templates/$module".$config['dircss'].$css);
            }
        }
        
        //Apply javascripts to layout
        if(count($config['filejs'])>0){      
            foreach ($config['filejs'] as $key => $js){
                $this->view->headScript()->appendFile(BASE_URL."/application/templates/$module".$config['dirjs'].$js,'text/javascript');
            }
        }
                
        $option=array(
            "layout"=>$config['layout'],
            "layoutPath"=>APPLICATION_PATH."/templates/$module");
        Zend_Layout::startMvc($option);          
    }
    
    public function preDispatch() {        
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {                                        
                $this->_redirect('admin/user/loginform');            
        }
    }
    
    public function paginatorAct($kq){
        $paginator = Zend_Paginator::factory($kq);
        $paginator->setItemCountPerPage(3);        
        $paginator->setPageRange(3);
        $currentPage = $this->_request->getParam('page',1);
        $paginator->setCurrentPageNumber($currentPage);
        $this->view->data=$paginator;        
    }
    
    public function indexAction(){
       //$this->_redirect("/admin/index/welcome"); 
    }            
           
    public function mancatAction(){
        $cat=new Admin_Model_Tintuccat;        
        $kq=$cat->getAll();
                
        $this->paginatorAct($kq);
    }
            
  
            
    public function addcatAction(){
        
    }
               
    public function hienthicatAction()
    {        
        $cat=new Admin_Model_Tintuccat;
        $id=$this->_request->getParam("id");        
        $cat_item=$cat->getWhere($id);                             
        if($cat_item['hienthi']==1)        
            $data=array('hienthi'=>0);            
        else        
            $data=array('hienthi'=>1);                                
        $cat->updateCat($data,$id);
        $this->_redirect("/admin/tintuc/mancat/");            
    }       
    
    public function formsearchtinAction()
    {        
        $form = new Admin_Form_Searchdm1;
        //$form->getElement('ok')->setLabel('Đăng nhập');        
        $this->view->form=$form;  
        $this->_helper->layout->disableLayout();
         
        //$this->view= new Zend_View();
        //$this->view->headMeta()->appendHttpEquiv('Content-Type','text/html; charset=UTF-8');
        //$this->view->headLink()->appendStylesheet(HOST_PATH."/public/css/style.css");                   
    }        
}

